package com.rrd.mex.dw.mr.babel.parser;

import com.rrd.mex.dw.utils.DateUtil;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.hfq.UploadBaseData;
import com.ucredit.babel.common.model.hfq.phonebook.UploadPhoneBookData;
import com.ucredit.babel.common.model.hfq.phonebook.UploadPhoneBookDetail;
import com.ucredit.babel.common.model.hfq.phonebook.UploadPhoneBookRecord;
import com.ucredit.babel.common.model.mexico.CommonPhoneDetectionRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;
import java.util.Date;
import java.util.List;


public class CommonPhoneDetectionRecordParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * adVanceAI常规号码检测信息
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        CommonPhoneDetectionRecord obj = (CommonPhoneDetectionRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful,1);
        sb.append(obj.getMessage() == null ? "" : obj.getMessage()).append(CRT001);
        sb.append(obj.getCode() == null ? "" : obj.getCode()).append(CRT001);
        sb.append(obj.getTransactionId()==null?"":obj.getTransactionId()).append(CRT001);
        sb.append(obj.getPricingStrategy()==null?"":obj.getPricingStrategy()).append(CRT001);
        sb.append(obj.getStatus()==null?"":obj.getStatus()).append(CRT001);
        sb.append(obj.getDataMessage()==null?"":obj.getDataMessage()).append(CRT001);
        sb.append(obj.getLastSeen()==null?"":obj.getLastSeen()).append(CRT001);
        sb.append(obj.getPhoto()==null?"":obj.getPhoto()).append(CRT001);
        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;

    }

    @Override
    public String getTableName() {
        return "kafka_babel_common_phone_detection_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.COMMON_PHONE_DETECTION.toString();
    }

    @Override
    public String getComment() {
        return "手机号码检测";
    }

    @Override
    public BaseModel getModel() {
        return new CommonPhoneDetectionRecord();
    }
}
